package algorithms;

public class PalindromManipulations {
	
	static boolean isPalindrome(int number) {
		boolean res = false;
		
		int reversed = 0;
		int temp = number;
		
		while (temp != 0) {
			int rest = temp % 10;
			temp /= 10;
			reversed = reversed * 10 + rest;
		}
		
		res = number == reversed;
		
		return res;
	}
	
	public static void main(String[] args) {
		int max = 0;
		for (int i = 999; i > 0; i--) {
			
			for (int j = i; j > 0; j--) {
				int n = i * j;
				if (isPalindrome(n)) {
					if (n > max) {
						max = n;
					} else {
						break;
					}
				}
			}
		}
		System.out.println(max);
	}
}
